﻿@{
    ViewData["Title"] = "车辆参数副表-数据导入";
    Layout = "_Layout_DisplayAll";
}


<table id="T_VehicleImportPara" lay-filter="T_VehicleImportPara" lay-even></table>


@section Scripts{


    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">


            <button class="layui-btn layui-btn-sm" lay-event="AddData">添加</button>
            <button class="layui-btn layui-btn-sm" lay-event="ReloadData">刷新</button>
        </div>
    </script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="Singeldel">删除</a>
    </script>

    <script>
        var user = "@ViewBag.User";

        layui.use(['element', 'layer', 'table', 'form'], function () {
            var element = layui.element;
            var table = layui.table;
            var $ = layui.jquery;
            var bodyAdd;
            var bodyEdit;
            var tableIns = table.render(
                {
                    elem: '#T_VehicleImportPara'
                    , toolbar: '#toolbarDemo'
                    , url: '@Url.Action("GetT_VehicleImportParaSetup", "Home")' //数据接口
                    , limit: 30
                    , even: true
                    , page: true //开启分页
                    , size: 'sm'
                    , cols: [[ //表头

                        { field: 'id', title: 'ID', width: '40', sort: true }

                        , { field: 'vehicleid', title: '车辆编号', width: '100', sort: true }
                        , { field: 'importinputpath', title: '半小时导入路径', width: '140', sort: true }
                        , { field: 'importresultpath', title: '单位里程导入路径', width: '140', sort: true }
                         , { field: 'importpuma', title: '单位里程导入', width: '80', sort: true }
                        , { field: 'importgps', title: '经纬度导入', width: '80', sort: true }
                        , { field: 'importbrake', title: '刹车导入', width: '80', sort: true }
                        , { field: 'importthrottle', title: '油门导入', width: '80', sort: true }
                        , { field: 'importspeed', title: '速度导入', width: '80', sort: true }
                        , { field: 'importstatistic', title: '统计值导入', width: '80', sort: true }
                        , { field: 'importimpact', title: '冲击导入', width: '80', sort: true }
                        , { field: 'importsteering', title: '转向导入', width: '80', sort: true }
                        , { field: 'importwft', title: 'WFT导入', width: '80', sort: true }
                        , { field: 'importengspd', title: '转速导入', width: '80', sort: true }
                        , { field: 'speedcolumnname', title: '车速名称', width: '80', sort: true }
                        , { field: 'enginespeed', title: '转速名称', width: '80', sort: true }
                        , { field: 'throttlecolumnname', title: '油门名称', width: '80', sort: true }
                        , { field: 'brakecolumnname', title: '制动名称', width: '80', sort: true }
                        , { field: 'whlangcolumnname', title: '转向角名称', width: '80', sort: true }
                        , { field: 'whlanggrcolumnname', title: '转向角加速度名称', width: '80', sort: true }
                        , { field: 'acczwhllf', title: '左前轮心加速度Z名称', width: '80', sort: true }
                        , { field: 'acczwhlrf', title: '右前轮心加速度Z名称', width: '80', sort: true }
                        , { field: 'acczwhllr', title: '左后轮心加速度Z名称', width: '80', sort: true }
                        , { field: 'accybody', title: '车身加速度Y名称', width: '80', sort: true }
                        , { field: 'accxbody', title: '车身加速度X名称', width: '80', sort: true }
                        , { field: 'importgpsreductiontimes', title: 'GPS导入降采样倍数', width: '100', sort: true }
                        , { field: 'importaccreductiontimes', title: '输入降采样倍数(弃用)', width: '100', sort: true }
                        , { field: 'importwftreductiontimes', title: '输出降采样倍数(弃用)', width: '100', sort: true }

                        , { fixed: 'right', title: '操作', width: '120', toolbar: '#barDemo' }
                    ]]
                });

            table.on('tool(T_VehicleImportPara)', function (obj) {
                var data = obj.data;
                //console.log(data);
                if (user == "Admin") {
                    if (obj.event === 'edit') {

                        layer.open({
                            type: 2,
                            title: '编辑车辆信息',
                            shadeClose: true,
                            shade: 0.8,
                            area: ['720px', '80%'],
                            content: '@Url.Action("T_VehicleImportPara_PopUp", "PopUp")', //iframe的url
                            btn: ['确认', '取消'],
                            yes: function (index) {
                                var vehicleidtext = bodyEdit.find('#vehicleid').val();
                                var id = data.id;//获得选中行的id值
                                var importinputpath = bodyEdit.find('#importinputpath').val();
                                var importresultpath = bodyEdit.find('#importresultpath').val();
                            
                                var importgpsreductiontimes = bodyEdit.find('#importgpsreductiontimes').val();
                                var importaccreductiontimes = bodyEdit.find('#importaccreductiontimes').val();
                                var importwftreductiontimes = bodyEdit.find('#importwftreductiontimes').val();

                                var speedcolumnname = bodyEdit.find('#speedcolumnname').val();
                                var throttlecolumnname = bodyEdit.find('#throttlecolumnname').val();
                                var brakecolumnname = bodyEdit.find('#brakecolumnname').val();
                                var whlangcolumnname = bodyEdit.find('#whlangcolumnname').val();
                                var whlanggrcolumnname = bodyEdit.find('#whlanggrcolumnname').val();
                                var acczwhllf = bodyEdit.find('#acczwhllf').val();
                                var acczwhlrf = bodyEdit.find('#acczwhlrf').val();
                                var acczwhllr = bodyEdit.find('#acczwhllr').val();
                                var accybody = bodyEdit.find('#accybody').val();
                                var accxbody = bodyEdit.find('#accxbody').val();
                                 var enginespeed = bodyEdit.find('#enginespeed').val();
                                if (vehicleidtext != "" && importinputpath != "" && importresultpath != "" 
                                    && importgpsreductiontimes != "" && importaccreductiontimes != ""&& importwftreductiontimes != "") 
                                {
                                    $.ajax({
                                        //请求方式
                                        type: "POST",
                                        //请求的媒体类型
                                        //contentType: "application/json;charset=UTF-8",
                                        //请求地址
                                        url: '@Url.Action("AddorEditSingleT_VehicleImportPara", "Home")',
                                        //数据，json字符串
                                        data: {
                                            id: id,
                                            vehicleidtext: vehicleidtext,
                                            importinputpath: importinputpath,
                                            importresultpath: importresultpath,
                                           
                                            importgpsreductiontimes: importgpsreductiontimes,
                                            importaccreductiontimes: importaccreductiontimes,
                                            importwftreductiontimes: importwftreductiontimes,


                                            importpumacheck: iframeEdit.importpumacheck ? 1 : 0,
                                            statisticimportcheck: iframeEdit.statisticimportcheck ? 1 : 0,
                                            gpsimportcheck: iframeEdit.gpsimportcheck ? 1 : 0,
                                            speedimportcheck: iframeEdit.speedimportcheck ? 1 : 0,
                                            throttleimportcheck: iframeEdit.throttleimportcheck ? 1 : 0,
                                            brakeimportcheck: iframeEdit.brakeimportcheck ? 1 : 0,
                                            steeringimportcheck: iframeEdit.steeringimportcheck ? 1 : 0,
                                            bumpimportcheck: iframeEdit.bumpimportcheck ? 1 : 0,
                                            wftimportcheck: iframeEdit.wftimportcheck ? 1 : 0,
                                            importengspdcheck: iframeEdit.importengspdcheck ? 1 : 0,
                                            speedcolumnname: speedcolumnname,
                                            throttlecolumnname: throttlecolumnname,
                                            brakecolumnname: brakecolumnname,
                                            whlangcolumnname: whlangcolumnname,
                                            whlanggrcolumnname: whlanggrcolumnname,
                                            acczwhllf: acczwhllf,
                                            acczwhlrf: acczwhlrf,
                                            acczwhllr: acczwhllr,
                                            accybody: accybody,
                                            accxbody: accxbody,
                                            enginespeed:enginespeed,
                                            method: "edit"
                                        },
                                        //请求成功
                                        success: function (result) {
                                            layer.msg(result + "请刷新页面");
                                            //不管有没有修改，都认为需要删除原缓存
                                             $.ajax({
                                                    type: "POST",
                                                    url: '@Url.Action("DeleteOtherMemory", "Home")',
                                                    data: {
                                                        vehicleidtext: data.vehicleid,
                                                    },
                                                    error: function (e) {
                                                        layer.msg(e);
                                                    }
                                                });
                                        },
                                        //请求失败，包含具体的错误信息
                                        error: function (e) {
                                            layer.msg(e);
                                        }
                                    });
                                    layer.close(index);
                                }
                                else {
                                    layer.msg('请填写必填项');
                                    //console.log(abscheck);
                                }


                            },
                            //成功打开编辑页面
                            success: function (layero, index) {

                                bodyEdit = layer.getChildFrame('body', index);//获得子frame的body里的元素
                                iframeEdit = window[layero.find('iframe')[0]['name']];


                                bodyEdit.find('#vehicleid').val(data.vehicleid);
                                bodyEdit.find('#importinputpath').val(data.importinputpath);
                                bodyEdit.find('#importresultpath').val(data.importresultpath);
                              
                                bodyEdit.find('#importgpsreductiontimes').val(data.importgpsreductiontimes);
                                bodyEdit.find('#importaccreductiontimes').val(data.importaccreductiontimes);
                                bodyEdit.find('#importwftreductiontimes').val(data.importwftreductiontimes);
                                bodyEdit.find('#speedcolumnname').val(data.speedcolumnname);
                                bodyEdit.find('#throttlecolumnname').val(data.throttlecolumnname);
                                bodyEdit.find('#brakecolumnname').val(data.brakecolumnname);
                                bodyEdit.find('#whlangcolumnname').val(data.whlangcolumnname);
                                bodyEdit.find('#whlanggrcolumnname').val(data.whlanggrcolumnname);
                                bodyEdit.find('#acczwhllf').val(data.acczwhllf);
                                bodyEdit.find('#acczwhlrf').val(data.acczwhlrf);
                                bodyEdit.find('#acczwhllr').val(data.acczwhllr);
                                bodyEdit.find('#accybody').val(data.accybody);
                                bodyEdit.find('#accxbody').val(data.accxbody);
                                bodyEdit.find('#enginespeed').val(data.enginespeed);

                                  if (data.importpuma === 1) {
                                    
                                    bodyEdit.find('#importpuma').prop('checked', true);
                                }
                                else {
                                    bodyEdit.find('#importpuma').removeAttr('checked');
                                }

                                if (data.importstatistic === 1) {
                                    
                                    bodyEdit.find('#statisticimport').prop('checked', true);
                                }
                                else {
                                    bodyEdit.find('#statisticimport').removeAttr('checked');
                                }
                                if (data.importgps === 1) {
                                    bodyEdit.find('#gpsimport').prop('checked', true);
                                }
                                else {
                                    bodyEdit.find('#gpsimport').removeAttr('checked');
                                }
                                if (data.importspeed === 1) {
                                    bodyEdit.find('#speedimport').prop('checked', true);
                                }
                                else {
                                    bodyEdit.find('#speedimport').removeAttr('checked');
                                }
                                if (data.importthrottle === 1) {
                                    bodyEdit.find('#throttleimport').prop('checked', true);
                                }
                                else {
                                    bodyEdit.find('#throttleimport').removeAttr('checked');
                                }
                                if (data.importbrake === 1) {
                                    bodyEdit.find('#brakeimport').prop('checked', true);
                                }
                                else {
                                    bodyEdit.find('#brakeimport').removeAttr('checked');
                                }
                                if (data.importsteering === 1) {
                                    bodyEdit.find('#steeringimport').prop('checked', true);
                                }
                                else {
                                    bodyEdit.find('#steeringimport').removeAttr('checked');
                                }
                                if (data.importimpact === 1) {
                                    bodyEdit.find('#bumpimport').prop('checked', true);
                                }
                                else {
                                    bodyEdit.find('#bumpimport').removeAttr('checked');
                                }
                                if (data.importwft === 1) {
                                    bodyEdit.find('#wftimport').prop('checked', true);
                                }
                                else {
                                    bodyEdit.find('#wftimport').removeAttr('checked');
                                }
                                if (data.importengspd === 1) {
                                    bodyEdit.find('#importengspd').prop('checked', true);
                                }
                                else {
                                    bodyEdit.find('#importengspd').removeAttr('checked');
                                }
                            }
                        });

                    }
                    else if (obj.event === 'Singeldel') {

                        layer.confirm('确定删除吗？', function (index) {
                            $.ajax({
                                //请求方式
                                type: "POST",
                                //请求的媒体类型
                                //contentType: "application/json;charset=UTF-8",
                                //请求地址
                                url: '@Url.Action("DeleteSingleT_VehicleImportPara", "Home")',
                                //数据，json字符串
                                data: {
                                    id: data.id
                                },
                                //请求成功
                                success: function (result) {
                                    layer.msg(result + "请刷新页面");
                                },
                                //请求失败，包含具体的错误信息
                                error: function (e) {
                                    layer.msg(e);
                                }
                            });
                            layer.close(index);
                        });


                    }
                }
                else {
                    window.location.href = "/Home/Error";
                }
            });

            table.on('toolbar(T_VehicleImportPara)', function (obj) {
                switch (obj.event) {

                    case 'AddData':
                        if (user == "Admin") {

                            layer.open({
                                type: 2,
                                title: '添加项目信息',
                                shadeClose: true,
                                shade: 0.8,
                                area: ['720px', '80%'],
                                content: '@Url.Action("T_VehicleImportPara_PopUp", "PopUp")', //iframe的url
                                btn: ['确认', '取消'],
                                yes: function (index) {
                                    var vehicleidtext = bodyEdit.find('#vehicleid').val();
                                    var importinputpath = bodyEdit.find('#importinputpath').val();
                                    var importresultpath = bodyEdit.find('#importresultpath').val();
                                  
                                    var importgpsreductiontimes = bodyEdit.find('#importgpsreductiontimes').val();
                                    var importaccreductiontimes = bodyEdit.find('#importaccreductiontimes').val();
                                    var importwftreductiontimes = bodyEdit.find('#importwftreductiontimes').val();
                                    var speedcolumnname = bodyEdit.find('#speedcolumnname').val();
                                    var throttlecolumnname = bodyEdit.find('#throttlecolumnname').val();
                                    var brakecolumnname = bodyEdit.find('#brakecolumnname').val();
                                    var whlangcolumnname = bodyEdit.find('#whlangcolumnname').val();
                                    var whlanggrcolumnname = bodyEdit.find('#whlanggrcolumnname').val();
                                    var acczwhllf = bodyEdit.find('#acczwhllf').val();
                                    var acczwhlrf = bodyEdit.find('#acczwhlrf').val();
                                    var acczwhllr = bodyEdit.find('#acczwhllr').val();
                                    var accybody = bodyEdit.find('#accybody').val();
                                    var accxbody = bodyEdit.find('#accxbody').val();
                                    var enginespeed = bodyEdit.find('#enginespeed').val();
                                    if (vehicleidtext != "" && importinputpath != "" && importresultpath != "" 
                                        && importgpsreductiontimes != "" && importaccreductiontimes != "" && importwftreductiontimes != "") {
                                        $.ajax({
                                            //请求方式
                                            type: "POST",
                                            //请求的媒体类型
                                            //contentType: "application/json;charset=UTF-8",
                                            //请求地址
                                            url: '@Url.Action("AddorEditSingleT_VehicleImportPara", "Home")',
                                            //数据，json字符串
                                            data: {
                                                vehicleidtext: vehicleidtext,
                                                importinputpath: importinputpath,
                                                importresultpath: importresultpath,
                                                importgpsreductiontimes: importgpsreductiontimes,
                                                importaccreductiontimes: importaccreductiontimes,
                                                importwftreductiontimes: importwftreductiontimes,
                                                speedcolumnname: speedcolumnname,
                                                throttlecolumnname: throttlecolumnname,
                                                brakecolumnname: brakecolumnname,
                                                whlangcolumnname: whlangcolumnname,
                                                whlanggrcolumnname: whlanggrcolumnname,
                                                acczwhllf: acczwhllf,
                                                acczwhlrf: acczwhlrf,
                                                acczwhllr: acczwhllr,
                                                accybody: accybody,
                                                accxbody: accxbody,
                                                enginespeed:enginespeed,
                                                importpumacheck: iframeEdit.importpumacheck ? 1 : 0,
                                                importengspdcheck: iframeEdit.importengspdcheck ? 1 : 0,
                                                statisticimportcheck: iframeEdit.statisticimportcheck ? 1 : 0,
                                                gpsimportcheck: iframeEdit.gpsimportcheck ? 1 : 0,
                                                speedimportcheck: iframeEdit.speedimportcheck ? 1 : 0,
                                                throttleimportcheck: iframeEdit.throttleimportcheck ? 1 : 0,
                                                brakeimportcheck: iframeEdit.brakeimportcheck ? 1 : 0,
                                                steeringimportcheck: iframeEdit.steeringimportcheck ? 1 : 0,
                                                bumpimportcheck: iframeEdit.bumpimportcheck ? 1 : 0,
                                                wftimportcheck: iframeEdit.wftimportcheck ? 1 : 0,
                                                method: "add"
                                            },
                                            //请求成功
                                            success: function (result) {
                                                layer.msg(result + "请刷新页面");
                                            },
                                            //请求失败，包含具体的错误信息
                                            error: function (e) {
                                                layer.msg(e);
                                            }
                                        });
                                        layer.close(index);
                                    }
                                    else {
                                        layer.msg('请填写必填项');
                                    }
                                },
                                //点击添加成功后出现的选项，有默认值
                                success: function (layero, index) {
                                    bodyEdit = layer.getChildFrame('body', index);
                                    iframeEdit = window[layero.find('iframe')[0]['name']];
                                    bodyEdit.find('#importgpsreductiontimes').val(32);
                                    bodyEdit.find('#importaccreductiontimes').val(1);
                                    bodyEdit.find('#importwftreductiontimes').val(1);
                                    bodyEdit.find('#speedcolumnname').val("spd");
                                    bodyEdit.find('#throttlecolumnname').val("EPTAccelActu");
                                    bodyEdit.find('#brakecolumnname').val("BrkPdlDrvrAp");
                                    bodyEdit.find('#whlangcolumnname').val("StrgWhlAng");
                                    bodyEdit.find('#whlanggrcolumnname').val("StrgWhlAng");
                                    bodyEdit.find('#acczwhllf').val("Acc_Z_Whl_LF");
                                    bodyEdit.find('#acczwhlrf').val("Acc_Z_Whl_RF");
                                    bodyEdit.find('#acczwhllr').val("Acc_Z_Whl_LR");
                                    bodyEdit.find('#accybody').val("Acc_Y_ST_LF");
                                    bodyEdit.find('#accxbody').val("Acc_X_ST_LF");
                                    bodyEdit.find('#enginespeed').val("enspdhsc1");
                                }
                            });
                        }
                        else {
                            window.location.href = "/Home/Error";
                        }

                        break;
                    case 'ReloadData':
                        tableIns.reload({
                            page: { curr: 1, limit: 30 },
                            url: '@Url.Action("GetT_VehicleImportParaSetup", "Home")',
                            method: 'post'
                        });
                        break;
                };
            });

        })


    </script>
}